package data
{
	import collection.DataCollection;
	
	import com.common.utils.HashMap;

	public class MapVO
	{
		public var id:String;
		public var bitmapClassname:String;
		public var rowNum:int;	//行数
		public var columnNum:int;	//列数
		public var gridWidth:int;
		public var gridHeight:int;
		public var arrPlayerPosition:Array; //地图开始初始化时  player和enemy的位置信息
		
		public var arrGridInfo:Array;
		
		public function MapVO(id:String, bitmapClassName:String, rowNum:int, columnNum:int, gridWidth:int, gridHeight:int)
		{
			this.id = id;
			this.bitmapClassname = bitmapClassName;
			this.rowNum = rowNum;
			this.columnNum = columnNum;
			this.gridWidth = gridWidth;
			this.gridHeight = gridHeight;
			
			arrGridInfo = [];
			arrPlayerPosition = [];
		}

		/**
		 * 
		 * @param blockStr			地格信息   0,0,1,0,0,0,1,1
		 * @param flyStr			跳转点信息      2,34@1,42
		 * @itemStr					地格中的物品信息  2001,0,0,2002,0
		 */		
		public function setGridInfo(blockStr:String, flyStr:String, itemStr:String):void
		{
			var arrGrid:Array = blockStr.split(',');
			var arrItem:Array = itemStr.split(',');
			var len:int = arrGrid.length;
			for (var i:int; i< len; i++)
			{
				var gridVO:GridVO = new GridVO(i, int(arrGrid[i]));
				var hmitems:HashMap = DataCollection.hmItems;
				if (arrItem[i] > 0)
				{
					//等于 0 表示这个id下的grid里没有物品
					gridVO.addItem((hmitems.get(arrItem[i]) as ItemVO).clone());
				}
				arrGridInfo.push(gridVO);
			}
			
			//初始化跳转点
			//97>109,110>98,27>51,167>43
			var arr:Array = flyStr.split(',');
			for (var j:int = 0; j< arr.length; j++)
			{
				var arr2:Array = (arr[j] as String).split('>');
				(arrGridInfo[arr2[0]]).setFly(arr2[1]);
			}
		}
		
		public function setPlayerInfo(strPlayerEnemy:String):void
		{
			//1001,16@1002,33@1003,24
			//string的第一个数字是player的位置， 其他是敌人的位置, 每组用@分割
			//如  1,16  表示player的类型是1, 位置为16
			var arr:Array = strPlayerEnemy.split('@');
			for (var i:int; i<arr.length; i++)
			{
				var str:String = arr[i];
				var arr2:Array = str.split(',');
				var o:Object = {id:arr2[0], positionIndex:arr2[1]};
				arrPlayerPosition.push(o);
			}
		}

	}
}